import { getBlogInfoAPI } from '@/api/blog'
import { createSlice } from '@reduxjs/toolkit'

const blogStore = createSlice({
    name: 'blog',
    initialState: {
        blogInfo: []
    },
    reducers: {
        setBlogInfo (state, action) {
            state.blogInfo = action.payload
        }
    }
})

const {setBlogInfo} = blogStore.actions
// 获取reducer函数
const blogReducer = blogStore.reducer

// 获取博客
const fetchBlogInfo = (id) => {
    return async (dispatch) => {
      const res = await getBlogInfoAPI(id)
      dispatch(setBlogInfo(res.data))
    }
  }

export { fetchBlogInfo }

export default blogReducer